package coml.jiyun.hp.day08;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class BallView extends View {

    private final Bitmap bitmap;
    private final Paint paint;
    private float mLeft;
    private float mTop;

    public BallView(Context context, AttributeSet attributeSet) {
        super(context);
        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ball);
        paint = new Paint();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //小球跟随者手指点的位置变化而变化
        canvas.drawBitmap(bitmap,mLeft,mTop,paint);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        mLeft = event.getX();
        mTop = event.getY();
        //重新绘制界面
        invalidate();

        return true;

    }
}
